<?php
// +----------------------------------------------------------------------
// | 终端撤改审核
// +----------------------------------------------------------------------
// | Author: TongBC <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/07/23
// +----------------------------------------------------------------------
include_once("/var/www/html/new/com.inc.php");
// exit('<script>alert("处理成功");window.close();</script>');



if(!isset($_SESSION['sid'])) exit('<script>alert("登陆超时，请重新登陆");</script>');





$ter_id = $_REQUEST['Did'] + 0;

$str = "select id,dstatus,lid,tid,tnum,ordernum,dadmin from `uu_order_terminal_change` where id=$ter_id order by id desc limit 1";
$GLOBALS['le']->query($str);
$dbRow = $GLOBALS['le']->fetch_assoc();
if($dbRow['dstatus']>0) exit('<script>alert("记录已处理");</script>');


// if($_SESSION['sid']!=$dbRow['dadmin']) exit('<script>alert("身份不合法");</script>');


$params['Did'] = $dbRow['id'];
$params['Dordernum'] = $dbRow['ordernum'];
$params['Dlid'] = $dbRow['lid'];
$params['Dtid'] = $dbRow['tid'];
$params['Dnum'] = $dbRow['tnum'];
$params['Ddadmin'] = $dbRow['dadmin'];// 分销商ID
$params['Ddstatus'] = $_REQUEST['Ddstatus'] + 0;
$params['Dreason'] = $_REQUEST['Dreason'];
// if($_SESSION['sid']==6970){
	// print_r($params);
	// exit;
// }
$res = raw_post('http://121.43.119.39/new/oop/terminal_change_NEW.php', $params);
if($res==100) exit('<script>alert("操作成功");window.location.href="../terchange.html";</script>');
write_logs($res);
write_logs(json_encode($_REQUEST));
exit('<script>alert("处理失败");window.location.href="../terchange.html";</script>');


function raw_post($url,$data){
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	return curl_exec($ch);
}

function write_logs($txt,$file='/var/www/html/new/d/abc/logs/6.txt'){
	$fp = fopen($file,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,date("Y-m-d H:i:s").":".$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
